<template>
    <el-dialog
        title="上传文件"
        :visible.sync="dialogVisible"
        v-loading="loading"
        :close-on-click-modal="false"
        width="800px">
        <div>
            <el-form ref="uploadForm" :model="uploadForm" :rules="rules" label-width="80px">
                <el-form-item label="专业类型" prop="majorType">
                    <el-select v-model="uploadForm.majorType" placeholder="请选择专业类型">
                        <el-option label="机加" value="1"></el-option>
                        <el-option label="微组装" value="2"></el-option>
                        <el-option label="焊接" value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="知识类型" prop="knowType">
                    <el-select v-model="uploadForm.knowType" placeholder="请选择专业类型">
                        <el-option label="机加" value="1"></el-option>
                        <el-option label="微组装" value="2"></el-option>
                        <el-option label="焊接" value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="附件上传" prop="fileId">
                    <preview-upload :showPreviewButton="true" :showDownloadButton="false" :showDeleteButton="true" :multiple="true" :isOnly="false" :lineNumber="4" :accessoryList="filesArr" @getValue="getAccessoryList"></preview-upload>
                </el-form-item>
            </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button size="small" @click="dialogVisible = false">取 消</el-button>
            <el-button size="small" type="primary" :loading="loadingAddButton" @click="fileSave">确 定</el-button>
        </div>
    </el-dialog>
</template>
<script>
import PreviewUpload from '@/components/accessory/PreviewUpload'
export default {
    name: 'UploadDialog',
    data() {
        return {
            dialogVisible: false,
            loading: false,
            loadingAddButton: false,
            uploadForm: {
                majorType: '',
                knowType: '',
                fileId: ''
            },
            rules: {
                majorType: [
                    { required: true, message: '请选择专业类型', trigger: 'change' }
                ],
                knowType: [
                    { required: true, message: '请选择知识类型', trigger: 'change' }
                ],
                fileId: [
                    { required: true, message: '上传文件不能为空', trigger: 'change' }
                ]
            },
            filesArr: []
        }
    },
    components: {
        PreviewUpload
    },
    methods: {
        init() {
            this.dialogVisible = true
            this.uploadForm.majorType = ''
            this.uploadForm.knowType = ''
            this.uploadForm.fileId = ''
            this.filesArr = []
            setTimeout(() => {
                this.$refs.uploadForm.resetFields()
            },10)
        },
        //附件
        getAccessoryList(val) {
            this.uploadForm.fileId = val.map((item) => item.accessoryId).toString()
        },
        //保存附件
        fileSave() {
            this.$refs.uploadForm.validate((valid) => {
                // if (valid) {
                //     this.loading = true
                //     this.loadingAddButton = true
                //     this.$http({
                //         url: '/userGrid/tools/save',
                //         method: 'POST',
                //         data: {
                //             ...this.uploadForm
                //         }
                //     }).then(({data}) => {
                //         if (data && data.success) {
                //             this.$parent.getFilesList()
                //         }
                //         this.loading = false
                //         this.loadingAddButton = false
                //         this.dialogVisible = false
                //     }).catch(() => {
                //         this.loading = false
                //         this.loadingAddButton = false
                //         this.$message.warning('保存失败，请重新上传保存！')
                //     })
                // } else {
                //     return false
                // }
            })
        }
    }
}
</script>
<style scoped></style>
